import { Alert, Avatar, Button, Card, DatePicker, Skeleton, Spin, Tooltip, message } from 'antd';
import moment from 'moment';
import React, { useEffect, useRef, useState } from 'react';
import ProDescriptions from '@ant-design/pro-descriptions';
import ProCard from '@ant-design/pro-card';
import { ActionType } from '@ant-design/pro-table';
import { businessDetail } from '@/services/api/api-analysis';
import { CopyOutlined } from '@ant-design/icons';
import copy from 'copy-to-clipboard';
const business: React.FC = ({ }) => {
    const startDate = moment().startOf('month');
    const endOfDate = moment();
    const [totalData, setTotalDataState] = useState<AnalysisData.Business>();
    const monthFormat = 'YYYY-MM-DD';
    const actionRef = useRef<ActionType>();
    const [loading, setLoadingState] = useState(true)
    //日期范围
    const [dataDates, setDataDatesState] = useState<string[]>([startDate.format(monthFormat), endOfDate.format(monthFormat)])
    const loadData = async () => {
        console.log(dataDates);
        try {
            const response = await businessDetail({ dates: dataDates });
            if (response.code === 0) {
                console.log(response.data);

                setTotalDataState(response.data);
                setLoadingState(false)
            }
        } catch (error) {
            console.log(error);
        }
    }
    const copyToClipboard = (text) => {
        copy(text);
    };
    useEffect(() => {
        loadData();
        actionRef?.current?.reload()
    }, [dataDates]);
    return (

        <ProCard
            title="业务分析"
            headerBordered
            bordered
            style={{ width: '100%', marginTop: '24px', }}
            extra={<DatePicker.RangePicker
                style={{width:220}}
                allowClear={false}
                defaultValue={[startDate, endOfDate]}
                format={monthFormat}
                disabledDate={(current) => {
                    return current && current > moment().endOf('day')
                }}
                onChange={(values, dates) => {
                    setDataDatesState(dates)
                    setLoadingState(true)
                }}
                ranges={{
                    今日: [moment(), moment()],
                    本月: [moment().startOf('month'), moment().endOf('month')],
                    上月: [
                        moment().startOf('month').subtract(1, 'months'),
                        moment().endOf('month').subtract(1, 'months'),
                    ],
                    最近7天: [moment().subtract(6, 'days'), moment()],
                    最近60天: [moment().subtract(59, 'days'), moment()],
                    最近90天: [moment().subtract(89, 'days'), moment()],
                    至今: [moment('2023-06-20'), moment()],
                }}
            />}

            colSpan={{ xs: 24, sm: 22, md: 22, lg: 22, xl: 22 }}
        >
            <Spin spinning={loading} size="large" >
                <ProDescriptions
                    title="选题数据"
                    actionRef={actionRef}
                    columns={[
                        {
                            title: '操作',
                            valueType: 'option',
                            render: () => [
                                <a target="_blank" rel="noopener noreferrer" key="link" onClick={() => { message.success('复制成功'), copyToClipboard(totalData?.analysisBusinessStr) }}>
                                    <CopyOutlined />复制
                                </a>
                            ],
                        },
                    ]}
                >
                    <ProDescriptions.Item label="上线服务" >
                        {totalData?.serviceTime}天
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="发布选题计划" >
                        {totalData?.countTopic}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="线索征集" >
                        {totalData?.countSubmit}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="选题征集线索收录跟踪" >
                        {totalData?.countSubmitAdoptAccount}人次
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="下辖镇街、驻区单位等共主动报送线索" >
                        {totalData?.countActive}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="线索收录" >
                        {totalData?.countActiveAdopt}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="主动报送线索收录跟踪" >
                        {totalData?.countActiveAdoptAccount}人次
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="全部上报线索" >
                        {totalData?.countAllCues}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="线索收录跟踪" >
                        {totalData?.countAllCuesAccount}人
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="累计产生" >
                        {totalData?.resourceSize}资源
                    </ProDescriptions.Item>
                </ProDescriptions>
                <ProDescriptions
                    title="宣传刊播"
                >
                    <ProDescriptions.Item label="收录数量" >
                        {totalData?.countPublish}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="中央媒体数量" >
                        {totalData?.countCentralMedia}条
                    </ProDescriptions.Item>
                    {/* <ProDescriptions.Item label="对外传播数量" >
                        {totalData?.countOverseasPublicity}条
                    </ProDescriptions.Item> */}
                    <ProDescriptions.Item label="市/区县级媒体" >
                        {totalData?.countMunicipalAndCountyMedia}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="对外文化推广" >
                        {totalData?.countCulturePromotion}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="未及时召开新闻发布会" >
                        {totalData?.countNewsRelease}场
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="媒情网情社情转交办事项回复" >
                        {totalData?.countMediaReply}次
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="文艺创作获奖" >
                        {totalData?.countLiteraryArtisticAwards}次
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="文艺作品展演展播展览" >
                        {totalData?.countLiteraryExhibition}次
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="文化遗产保护传承整体效能得分" >
                        {totalData?.scoreCulturalHeritageProtection}分
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="博物馆服务效能得分" >
                        {totalData?.scoreMuseumService}分
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="区县级文物“四有”及文物巡查得分" >
                        {totalData?.scoreCulturalRelicPatrol}分
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="签到推广数量" >
                        {totalData?.countPromotion}条
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="推广传播人数" >
                        {totalData?.countPromotionAccount}人次
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="常驻单位数量" >
                        {totalData?.countResidentUnit}个
                    </ProDescriptions.Item>

                </ProDescriptions>
                <ProDescriptions
                    title="用户数据"
                >
                    <ProDescriptions.Item label="用户数量" >
                        {totalData?.countAccount}人
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="登录次数" >
                        {totalData?.countLogin}次
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="融媒通小程序累计用户" >
                        {totalData?.countMiniProgramAccount}人
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="服务号关注人数" >
                        {totalData?.countFollowersAccount}人
                    </ProDescriptions.Item>
                </ProDescriptions>
            </Spin >
        </ProCard>

        // <PageContainer
        //     title={false}
        //     header={{
        //         breadcrumb: {},
        //     }}
        // >
        // </PageContainer>
    );
};
export default business;